package com.school.common.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
 * @author gaobiao
 * 
 */
public class SystemConfUtils {
	private static Properties properties = null;
	private static final String CONFIG_FILENAME = "systemconf.properties";

	static {
		loadProperties();
	}

	private synchronized static void loadProperties() {
		if (properties == null) {
			try {
				File file = new File(SystemConfUtils.class.getResource("/" + CONFIG_FILENAME).getPath());
				FileInputStream fis = new FileInputStream(file);
				try {
					properties = new Properties();
					properties.load(fis);
				} catch (Exception e) {
					properties = null;
				} finally {
					fis.close();
				}

			} catch (FileNotFoundException e) {

				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {

				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public static String getProperty(String name) {
		try {
			return properties.getProperty(name);
		} catch (Exception ex) {
			return "";
		}
	}
}
